package com.gonsin.gview.model.dynamic.data;

import com.gonsin.gview.annotations.interfaces.ITableDataPicker;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class DynamicTableData {

    @ApiModelProperty("主键的字段名称")
    private String keyName;

    @ApiModelProperty("通过dataPicker的类名写java语句查询数据")
    private String fromTableDataPickerClassName;
    public static DynamicTableDataBuilder fromTableDataPickerClassName(String fromTableDataPickerClassName){
        DynamicTableDataBuilder data = new DynamicTableDataBuilder();
        data.fromTableDataPickerClassName = fromTableDataPickerClassName;
        return data;
    }

    @ApiModelProperty("通过dataPicker写java语句查询数据（此方法最为灵活）")
    private Class<? extends ITableDataPicker> fromTableDataPicker;
    public static DynamicTableDataBuilder fromTableDataPicker(Class<? extends ITableDataPicker> fromTableDataPicker){
        DynamicTableDataBuilder data = new DynamicTableDataBuilder();
        data.fromTableDataPicker = fromTableDataPicker;
        return data;
    }

    @ApiModelProperty("主键的字段名称")
    private String fromDataSource;
    public static DynamicTableDataBuilder fromDataSource(String fromDataSource){
        DynamicTableDataBuilder data = new DynamicTableDataBuilder();
        data.fromDataSource = fromDataSource;
        return data;
    }


    public static final class DynamicTableDataBuilder {
        private String keyName;
        private String fromTableDataPickerClassName;
        private Class<? extends ITableDataPicker> fromTableDataPicker;
        private String fromDataSource;

        private DynamicTableDataBuilder() {
        }

        public DynamicTableDataBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicTableData build() {
            DynamicTableData dynamicTableData = new DynamicTableData();
            dynamicTableData.setKeyName(keyName);
            dynamicTableData.setFromTableDataPickerClassName(fromTableDataPickerClassName);
            dynamicTableData.setFromTableDataPicker(fromTableDataPicker);
            dynamicTableData.setFromDataSource(fromDataSource);
            return dynamicTableData;
        }
    }
}
